/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.report.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.koron.common.domain.DataBean;
import com.koron.report.bean.UserTaskAnalysis;
import com.koron.report.service.api.HiddenDangerDiscoveryAnalysisService;
import com.koron.report.service.api.UserTaskAnalysisService;
import com.koron.report.util.BusinessCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;

import java.util.Date;

@Api(tags = "userTaskAnalysis",description = "任务统计分析")
@RestController
@RequestMapping("/userTaskAnalysis")
public class UserTaskAnalysisController {
    @Autowired
    private HiddenDangerDiscoveryAnalysisService dangerDiscoveryAnalysisService;

    @Autowired
    private UserTaskAnalysisService userTaskAnalysisService;

    @ApiOperation("查询某个层级下各子层级任务统计分析列表接口，可根据查询集团、片区，水司")
    @ApiImplicitParams({
            @ApiImplicitParam(name="orgCode",value = "集团/水司/网格编码，查询集团是编码可为空" ,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name="updateTimeStart",value = "开始时间" ,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name="updateTimeEnd",value = "结束时间" ,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name="page",value = "当前页",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name="pageSize",value = "每页条数",required = true,dataType = "int",paramType = "query")
    })
    @RequestMapping(value = "/getUserTaskAnalysisListByLevel.htm",method = RequestMethod.POST)
    public MessageBean<DataBean<UserTaskAnalysis>> getUserTaskAnalysisListByLevel(@RequestParam(required = false) String orgCode, @RequestParam(required = false) final @JsonFormat(pattern="yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd") Date updateTimeStart, @RequestParam(required = false) final @JsonFormat(pattern="yyyy-MM-dd")
                                                                                              @DateTimeFormat(pattern="yyyy-MM-dd")   Date updateTimeEnd, @RequestParam(required = true)Integer page, @RequestParam(required = true)Integer pageSize){
        Integer orgLevel=dangerDiscoveryAnalysisService.checkLevel(orgCode);
        if (orgLevel==null||orgLevel>=3||orgLevel<0){
            MessageBean<DataBean<UserTaskAnalysis>> msg=new MessageBean<>();
            msg.setCode(BusinessCode.ILEGAL_ORGLEVEL.getCode());
            msg.setDescription(BusinessCode.ILEGAL_ORGLEVEL.getDescription());
            return msg;
        }
        return userTaskAnalysisService.getUserTaskAnalysisListByLevel(orgLevel,orgCode,updateTimeStart,updateTimeEnd,page,pageSize);
    }

//    @ApiOperation("查询所有开通水司任务统计分析列表接口")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name="updateTimeStart",value = "开始时间" ,dataType = "String",paramType = "query"),
//            @ApiImplicitParam(name="updateTimeEnd",value = "结束时间" ,dataType = "String",paramType = "query"),
//            @ApiImplicitParam(name="page",value = "当前页",required = true,dataType = "int",paramType = "query"),
//            @ApiImplicitParam(name="pageSize",value = "每页条数",required = true,dataType = "int",paramType = "query")
//    })
//    @RequestMapping(value = "/getUserTaskAnalysisListByCorp.htm",method = RequestMethod.POST)
//    public MessageBean<DataBean<UserTaskAnalysis>> getUserTaskAnalysisListByCorp(@RequestParam(required = false) final @JsonFormat(pattern="yyyy-MM-dd") @DateTimeFormat(pattern="yyyy-MM-dd") Date updateTimeStart, @RequestParam(required = false) final @JsonFormat(pattern="yyyy-MM-dd")
//    @DateTimeFormat(pattern="yyyy-MM-dd")   Date updateTimeEnd, @RequestParam(required = true)Integer page, @RequestParam(required = true)Integer pageSize){
//        return userTaskAnalysisService.getUserTaskAnalysisListByCorp(updateTimeStart,updateTimeEnd,page,pageSize);
//    }
}
